package com.example.myapplication

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL

        val textView = TextView(this)
        textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize = 30f
        textView.text = getString(R.string.textView)
        linearLayout.addView(textView)

        val button =Button(this)
//        textView.width = ViewGroup.LayoutParams.MATCH_PARENT
//        textView.height = ViewGroup.LayoutParams.WRAP_CONTENT
        button.text = getString(R.string.button)
        linearLayout.addView(button)

        val imageView = ImageView(this)
        val drawable = getDrawable(R.drawable.flag)
        imageView.setImageDrawable(drawable)
        linearLayout.addView(imageView)

        setContentView(linearLayout)

        button.setOnClickListener {
//            val textView = findViewById<TextView>(R.id.textView)
            textView.text = resources.getString(R.string.clicked)
        }

        ViewCompat.setOnApplyWindowInsetsListener(linearLayout) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

    }

}
